<?php
// Script to display a PHP class or lib manual using the Manta doc (Mdoc) class.
require("./config.php");

// Load required Manta classes
if ($force_php4 
    || version_compare(phpversion(), "5") < 0) {
  $mantalibpath = dirname(__FILE__) . "/../include/php4/";
} else {
  $mantalibpath = dirname(__FILE__) . "/../include/php5/";
}
require($mantalibpath. "Mdoc.php");

// Define the alternative file paths to the PHP code to document (relative to DOCUMENT_ROOT)
$alt_dir['manta'] = $mantalibpath;

// Set current (requested) directory
if (!empty($_GET['path']) && $_GET['path'] == "manta") {
   $current_dir = $manta_lib_path;
} else {
   $current_dir = dirname(__FILE__) . "/samples/";;  // default samples path
}

// Library or class file name is required
if (!empty($_GET['file'])) {
  $ref_file = $_GET['file'];
  $ref_file_path = $current_dir . $ref_file . ".php";
} else {
  die("INVALID REQUEST");
}

// The tree view can be reduced to a branch
if (!empty($_GET['branch'])) {
  $view_branch = $_GET['branch'];
} else {
  $view_branch = "";
}

// Buid requested manual
$manual = new Mdoc($ref_file_path);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>phpManta - Mdoc - View internal documentation tree</title>
</head>

<body>
<h1>View Mdoc internals of <?php echo $ref_file; ?></h1>
<pre>
<?php 
  if (!empty($view_branch)) {
    echo "<h2>Branch <i>$view_branch</i></h2>\n";
  }
  print_r($manual->get_tree($view_branch));
?>
</pre>
<?php 
  // Display parser log if not empty
  if (!empty($manual->parser_log)) {
    echo "<hr />\n";
    echo "<pre style=\"color: #000099\">\n";
    echo "<b>Parsing errors:</b>\n";
    $manual->uparse_exportlog(true); 
    echo "</pre>";
  }
?>
</body>
</html>
